<?php 
// +----------------------------------------------------------------------
// | ThinkSNS
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.thinksns.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: nonant <nonant@thinksns.com>
// +----------------------------------------------------------------------
// 
//include './apps/home/lib/Model/SpaceModel.class.php';
class BaseInfoModel extends SpaceModel{
	
	/**
	 +----------------------------------------------------------
	 * Description 初始化用户资料信息
	 +----------------------------------------------------------
	 * @author Nonant nonant@thinksns.com
	 +----------------------------------------------------------
	 * @param int $uid  用户ID
	 * @param string $cardId  用户工号
	 +----------------------------------------------------------
	 * @return boolen
	 +----------------------------------------------------------
	 * Create at  2010-1-20 上午10:26:48
	 +----------------------------------------------------------
	 */
	function init_Base_Info($uid,$cardId,$data,$space=array()){
		if(0==$this->table(C('DB_PREFIX')."space")->where('uid='.$uid)->count()){
			//初始化空间
			$this->query("INSERT INTO ".C('DB_PREFIX')."space (uid,cardId,credit_score) values ('$uid','$cardId',200)");
			$this->query("INSERT INTO ".C('DB_PREFIX')."space_info (uid) values ('$uid')");
			$this->save_Base_Data($uid,'baseinfo',$data,$space);
			unset($_SESSION['NEED_ACTIVE']);
			return true;
		}else{
			return false;
		}
	}
	
	function get_Hrbi_info($cardId){
		$pHrbi = X('Hrbi');
		$pHrbi->setOutputType('decoded_json');
		$hrbiInfo = $pHrbi->getPersonDetail($cardId,1);
		if($hrbiInfo->errorInfo){
			return false;
		}else{
			return $hrbiInfo;
		}
	}
	
	/**
	 +----------------------------------------------------------
	 * Description 转化成网站数据
	 +----------------------------------------------------------
	 * @author Nonant nonant@thinksns.com
	 +----------------------------------------------------------
	 * @param String $cardId   员工卡号
	 * @param String $lang     语言 zh=简体中文 en=英文
	 +----------------------------------------------------------
	 * @return array
	 +----------------------------------------------------------
	 * Create at  2010-1-19 上午11:39:31
	 +----------------------------------------------------------
	 */
	function get_Hrbi_Info_Data($cardId,$lang='zh'){
	   $list = $this->info_Field_list('baseinfo');
	   $hrbi = $this->hrbi_Field_parse($this->get_Hrbi_info($cardId,$lang));
	   foreach ($list as $key=>$value){
	   		$list[$key]['value'] = $hrbi[$key];
	   		$list[$key]['info']  = $list[$key]['info'];
	   		$list[$key]['field'] = $key;
	   }
	   return $list;
	}

	/**
	 * 
	 */
	
	function get_Hrbi_Info_have_Data($hrbi){
	   $list = $this->info_Field_list('baseinfo');
	   $hrbi = $this->hrbi_Field_parse( $hrbi );
	   foreach ($list as $key=>$value){
	   		$list[$key]['value'] = $hrbi[$key];
	   		$list[$key]['info']  = $list[$key]['info'];
	   		$list[$key]['field'] = $key;
	   }
	   return $list;
	}

	/**
	 +----------------------------------------------------------
	 * Description 解析Hrbi数据
	 +----------------------------------------------------------
	 * @author Nonant nonant@thinksns.com
	 +----------------------------------------------------------
	 * @param Object $hrbi Hrbi信息
	 +----------------------------------------------------------
	 * @return array
	 +----------------------------------------------------------
	 * Create at  2010-1-19 上午11:36:54
	 +----------------------------------------------------------
	 */
	protected function hrbi_Field_parse($hrbi){
		return array(
			'cardId'         => $hrbi->employee_Number,
			'username'       => $hrbi->last_Name,
			'department'     => "$hrbi->l1_Name/$hrbi->upper_Name/$hrbi->name",
			'shortname'      => $hrbi->short_Name,
			'usersex'        => ($hrbi->sex=='F')?'MM':'GG',
			'englishname'    => ( $hrbi->english_Name ) ? $hrbi->english_Name : $hrbi->last_Name ,
			'useremail'      => $hrbi->person_Mail,
			'userphone'      => ($hrbi->person_Phone_Code=='')?'':"$hrbi->person_Phone_Code($hrbi->person_Internal_Code)",
			'usermobile'     => ($hrbi->person_Mobile_Code=='')?'':$hrbi->person_Mobile_Code,
			'userfax'        => ($hrbi->person_Fax_Code=='')?'':$hrbi->person_Fax_Code,
			'userroom'       => str_replace("\\",'',$hrbi->person_Room)."/".$hrbi->person_Location,
			//'noteid'         => $hrbi->person_Notesid,
			//'differencetime' => $hrbi->person_Difference_Time,
		);
	}
	
	/**
	 +----------------------------------------------------------
	 * Description 解析Hrbi数据
	 +----------------------------------------------------------
	 * @author Nonant nonant@thinksns.com
	 +----------------------------------------------------------
	 * @param Object $hrbi Hrbi信息
	 +----------------------------------------------------------
	 * @return array
	 +----------------------------------------------------------
	 * Create at  2010-1-19 上午11:36:54
	 +----------------------------------------------------------
	 */
	
	//更新用户基本信息
	
	
}
?>